import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/user_entity.dart';
import 'package:xiongan_app_yy/provider/out_warehousing_provider.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/widgets/comm/text_card_widget.dart';

//作业功能入口
class TaskListPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TaskListPageState();
  }
}

class TaskListPageState extends State<TaskListPage> {
  List imageList = [
    "assets/images/into_warehousing.png",
    "assets/images/out_warehousing.png",
    //"assets/images/function01.png",
    //"assets/images/function02.png",
    //"assets/images/function03.png",
    //"assets/images/function04.png",
    "assets/images/function05.png",
    "assets/images/function06.png",
    "assets/images/function07.png",
    "assets/images/function08.png",
    "assets/images/lib_back.png"
  ];
  List titleList = [
    "入库作业",
    "出库作业",
    "移库作业",
    "盘库作业",
    "空托叠盘",
    "执行抽样",
    "样品回库",
  ];
  List<Border> borderList = [
    Border(
        bottom: BorderSide(width: 1, color: Color(0xffdddddd)),
        right: BorderSide(width: 1, color: Color(0xffdddddd))),
    Border(bottom: BorderSide(width: 1, color: Color(0xffdddddd)))
  ];
  Border drawBorder;
  List routeList = [
    "/into_warehousing",
    "/out_warehousing",
    //"/invCounterList",
    //"/auto_mounting",
    //"/auto_picking",
    //"/toreview",
    "/move_library",
    "/inventoryopr",
    "/empty_stacking",
    "/executive_sampling",
    "/lib_back"
  ];
  bool flag = true; //是否弹无权限toast
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
          backgroundColor: Color(0XFF00A5F1),
          title: Text(
            "作业",
            style: TextStyle(fontSize: 18),
          ),
          elevation: 0,
          centerTitle: true,
        ),
        body: GridView.builder(
            itemCount: titleList.length,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3, //横轴三个子widget
                childAspectRatio: 0.9 //宽高比为1时，子widget
                ),
            itemBuilder: (BuildContext context, int index) {
              if (index % 3 == 0) {
                drawBorder = borderList.elementAt(0);
              } else if (index % 3 == 1) {
                drawBorder = borderList.elementAt(0);
              } else if (index % 3 == 2) {
                drawBorder = borderList.elementAt(1);
              }
              ;
              return GestureDetector(
                child: Container(
                    decoration:
                        BoxDecoration(border: drawBorder, color: Colors.white),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Container(
                            padding: EdgeInsets.only(left: 38, right: 38),
                            child: Image.asset(imageList.elementAt(index),
                                fit: BoxFit.fill)),
                        Container(
                          child: Text(titleList.elementAt(index)),
                        )
                      ],
                    )),
                onTap: () {
                  for (int i = 0; i < DataSingleton().Data.appModuleMenusList.length; i++) {
                    UserAppmodulemenuslistMenutreedto bean = DataSingleton().Data.appModuleMenusList.elementAt(i).menuTreeDto;
                    print(bean.toJson().toString());
                    for (int j = 0; j < bean.nezadaTreeList.length; j++) {
                      if (titleList.elementAt(index) == bean.nezadaTreeList.elementAt(j).nodeName) {
                        Navigator.pushNamed(context, routeList.elementAt(index));
                        flag = false;
                        break;
                      }
                    }
                  }
                  if (flag) {
                    TostUtil.showToast("无权限");
                  }
                },
              );
            })

        /* ListView(
        children: <Widget>[
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/invCounter");
              },
              title: "清点与贴标"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/auto_mounting");
              },
              title: "自动上架"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/auto_picking");
              },
              title: "自动拣选"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/toreview");
              },
              title: "复核"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/move_library");
              },
              title: "移库作业"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/inventoryopr");
              },
              title: "盘库作业"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/empty_stacking");
              },
              title: "空盘叠盘"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/executive_sampling");
              },
              title: "执行抽样",
              border: Border.fromBorderSide(BorderSide.none)),
        ],
      ),*/
        );
  }
}
